home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / mac / Chapter Tutorials / CaseStudies / ch10.macromedia / brain.dcr / 00010_QMs Parent Script.ls < prev    next >
Encoding:
Text File  |  1996-11-12  |  2.6 KB  |  86 lines

  1. property pState, pFloatTime, pVelocityH, pVelocityV, pMySprite, pMyListPosition, pLifeTime, pMySize, p1stCastNum, pLastCastNum, pDirection
  2. global gTrackingList, cBound, cQMOffset, gReleaseTime
  3.  
  4. on new me, listPosition
  5.   set pMyListPosition to listPosition
  6.   set pMySprite to pMyListPosition + cQMOffset
  7.   set pState to 0
  8.   set pVelocityH to random(7)
  9.   set pVelocityV to random(7)
  10.   return me
  11. end
  12.  
  13. on liberateQM me
  14.   setAt(gTrackingList, pMyListPosition, 1)
  15.   set startH to randomInRange(getAt(cBound, 1), getAt(cBound, 3))
  16.   set startV to randomInRange(getAt(cBound, 2), getAt(cBound, 4))
  17.   set the loc of sprite pMySprite to point(startH, startV)
  18.   set gReleaseTime to the ticks
  19.   set pState to 1
  20.   set randNum to random(2) - 1
  21.   if randNum then
  22.     set p1stCastNum to 25
  23.     set pLastCastNum to 51
  24.     set pDirection to -1
  25.   else
  26.     set p1stCastNum to 51
  27.     set pLastCastNum to 25
  28.     set pDirection to 1
  29.   end if
  30.   set pFloatTime to the ticks
  31.   set pLifeTime to randomInRange(1800, 3600)
  32. end
  33.  
  34. on QMAction me
  35.   if pState then
  36.     set currentPositionH to the locH of sprite pMySprite + pVelocityH
  37.     set currentPositionV to the locV of sprite pMySprite + pVelocityV
  38.     if currentPositionH < getAt(cBound, 1) then
  39.       set pVelocityH to -1 * pVelocityH
  40.       set currentPositionH to getAt(cBound, 1)
  41.     end if
  42.     if currentPositionV < getAt(cBound, 2) then
  43.       set pVelocityV to -1 * pVelocityV
  44.       set currentPositionV to getAt(cBound, 2)
  45.     end if
  46.     if currentPositionH > getAt(cBound, 3) then
  47.       set pVelocityH to -1 * pVelocityH
  48.       set currentPositionH to getAt(cBound, 3)
  49.     end if
  50.     if currentPositionV > getAt(cBound, 4) then
  51.       set pVelocityV to -1 * pVelocityV
  52.       set currentPositionV to getAt(cBound, 4)
  53.     end if
  54.     if the castNum of sprite pMySprite = p1stCastNum then
  55.       set the castNum of sprite pMySprite to pLastCastNum
  56.     else
  57.       set the castNum of sprite pMySprite to the castNum of sprite pMySprite + pDirection
  58.     end if
  59.     set the loc of sprite pMySprite to point(currentPositionH, currentPositionV)
  60.     checkFloatTime()
  61.   end if
  62.   updateStage()
  63. end
  64.  
  65. on checkFloatTime me
  66.   set howLong to the ticks - pFloatTime
  67.   if howLong > pLifeTime then
  68.     set pState to 0
  69.     setAt(gTrackingList, pMyListPosition, 0)
  70.     set the loc of sprite pMySprite to point(-1000, -1000)
  71.   end if
  72. end
  73.  
  74. on changVelocities me, whichOne
  75.   if whichOne then
  76.     set tempList to [1, -1]
  77.     set pVelocityH to random(7) * getAt(tempList, random(2))
  78.     set pVelocityV to random(7) * getAt(tempList, random(2))
  79.   else
  80.     set pVelocityH to 1
  81.     set pVelocityV to 7
  82.     set gAllTogetherNow to 1
  83.     set the locV of sprite pMySprite to getAt(cBound, 4)
  84.   end if
  85. end
  86.